﻿using Corina.Common;
using Corina.DataContext.Master;
using Corina.Datamodel.Base;
using Corina.Datamodel.DataObject;
using Corina.Datamodel.Entities;
using Corina.Enumerations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Corina.Webservice.Cydee
{
    /// <summary>
    /// Summary description for DeviceMeasure
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class DeviceMeasure : WebserviceBase
    {
        #region Message
        [WebMethod]
        public ResultInfo GetAllDeviceMessage(string account, string password, string deviceSn, int kindId, string key, bool searchAll, int index, int size)
        {
            return GetInstance<DeviceMessageMaster>().GetAllItems(account, password, deviceSn, kindId, key, searchAll, index, size);
        }

        [WebMethod]
        public ResultInfo InsertDeviceMessage(string deviceSn, string content, string proofValue, TransTypeValue transType, string mobileOrIP, int smsId)
        {
            DeviceMessageInfo entity = new DeviceMessageInfo() { DeviceSn = deviceSn, Content = content, SmsId = smsId, ProofValue = proofValue, MobileOrIP = mobileOrIP, TransType = transType };
            return GetInstance<DeviceMessageMaster>().Insert(entity);
        }

        [WebMethod]
        public ResultInfo GetDeviceMessageInfo(string account,string password,int id)
        {
            return GetInstance<DeviceMessageMaster>().GetEntity(account, password, id);
        }

        [WebMethod]
        public ResultInfo RemoveDeviceMessage(string account,string password,int id)
        {
            return GetInstance<DeviceMessageMaster>().Remove(account, password, id);
        }

        [WebMethod]
        public ResultInfo ResolveDeviceMessage(string account, string password, int id)
        {
            return GetInstance<DeviceMessageMaster>().Resolve(account, password, id);
        }
        #endregion

        #region Measure
        [WebMethod]
        public ResultInfo GetAllDeviceMeasure(string account, string password, string deviceSn, int kindId, int userId, string name, bool onlyOpen, int index, int size)
        {
            return GetInstance<DeviceMeasureMaster>().GetAllItems(account, password, deviceSn, kindId, userId, name, onlyOpen, index, size);
        } 

        [WebMethod]
        public ResultInfo ChangeDeviceMeasureAvailability(string account, string password, int id, bool isopen)
        {
            return GetInstance<DeviceMeasureMaster>().ChangeAvailability(account, password, id, isopen);
        }

        [WebMethod]
        public ResultInfo RemoveDeviceMeasure(string account, string password, int id)
        {
            return GetInstance<DeviceMeasureMaster>().Remove(account, password, id);
        }

        [WebMethod]
        public ResultInfo InsertBatchDeviceMessage(string account, string password, string deviceSn, string content, string ipOrMobile)
        {
            return GetInstance<DeviceMessageMaster>().Insert(account, password, deviceSn, content, ipOrMobile);
        }
        #endregion

        #region ThirdParty
        [WebMethod]
        public ResultInfo GetThirdPartyItems(string account, string password, int userId, string specimen, int specimenKind, string measureObject, string applyUnit, string conditions, int index, int size)
        {
            List<QueryCondition> _conditions = string.IsNullOrEmpty(conditions) ? new List<QueryCondition>() : JsonHelper.Parse<List<QueryCondition>>(conditions);

            return GetInstance<ThirdPartyMeasureMaster>().GetAllManagedItems(account, password, userId, specimen, specimenKind, measureObject, applyUnit, _conditions, index, size);
        }
        #endregion
    }
}
